#pragma once
#include <list>
#include <string>
#include "JFile.h"
#include "JSerialize.h"
#include "JWorkingCopiesBaseFile.h"
#include "JOperateFileResult.h"
#include "JStubArgument.h"
class JWorkingCopies : public JSerialize,public JStubArgument
{
public:
	JWorkingCopies(); 
	~JWorkingCopies(void);
	std::string CreateWorkingCopies(std::string rootUrl,std::string author,std::string password,std::string _fullPath);
	JOperateFileResult FileStatus(std::string fileName);
	JOperateFileResult AddFile(std::string fileName,bool isRecurse);
	JOperateFileResult DeleteFile(std::string fileName);
	JOperateFileResult ModifyFile(std::string oldFileName,std::string newFileName);
	//bool IsInWorkingCopies(std::string fileName);
	bool IsInSubWorkingPath(std::string fullFileName);
	//std::list<std::string> GetAllFileNames();
	int Serialize(JInOutPut& _strea,int& allSize);
	int ReSerialize(JInOutPut& strea);
        
	int SerializeWithFile(JInOutPut& _strea,int& allSize);
	//return root path. If it isn't a working child path, return empty string.
        /*设置rootDir,jsvnPath,jsvnFileName,反序列化*/
	void BasicOperateInit(std::string currentWorkingPath);
        //得到copiesFile中_filePath的子目录
        std::list<JWorkingCopiesBaseFile*> GetChildCopiesFile(std::string _filePath);
        /*到远程服务器，建包*/
        int PackStubMessage(JInOutPut& _strea,int& _allSize);
        /*服务器解包*/
        int UnPackStubMessage(JInOutPut& _strea);
        std::string GetUserName();
        std::string GetPassword();
        std::string GetRootDir();
private:
	bool IsBaseFileValidate(std::string _fullFileName);
	JOperateFileResult AddFile(std::list<std::string> _fullFileNames);
        /*标识文件是否改变，如果改变就需要重新Serialize*/
	bool IsChanged;
        /*需不需要调用BasicOperateInit来对一些值进行赋值，因为在修改文件时（delete,add）,不用重复读取这些值*/
	bool needInitOperation;
        /*转化成绝对路径*/
        static std::string ConvertFullFileName(std::string _fileName);

	
	std::string ConvertToFullWorkingFileName(std::string _fullFileName);
	bool IsInWorkingPath(std::string _fileName);
	static std::string FindRootDir(std::string currentWorkingPath);
	//std::list<std::list<JWorkingCopiesBaseFile>::iterator > FileInPath(std::string _filePath);
	std::string jsvnPath;
	std::string jsvnFileName;
	//Need Serialize begin.
	std::string rootUrl;
	std::string author;
	std::string password;
        /*jsvn的目录名称*/
	std::string rootDir;
	std::list<JWorkingCopiesBaseFile> copiesFile;

	//std::list<std::string> copiesFileName;
	//Need Serialize end.
	void CreateWorkingCopiesDir();
	void CreateWorkingCopiesFile();
	void SaveWorkingCopiesToFile();
        //因为加入的时候copiesFile里面的顺序不同，所以需要对copiesFile进行排序
        void SortCopiesFile();
};

